package com.moli.iov.task.jobhandler;


import com.moli.iov.base.remote.InitCacheRemoteService;
import com.moli.iov.rest.RestResponse;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHander;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Component;

/**
 * 初始化basa服务缓存
 *
 * @author wanghualin
 * @date 2019 -10-22 15:26:22
 */
@Slf4j
@JobHander(value="initIovServiceBaseCacheJobHandler")
@Component
public class InitIovServiceBaseCacheJobHandler extends IJobHandler {

  @Resource
  private InitCacheRemoteService initCacheRemoteService;

  @Override
  public ReturnT<String> execute(String... params) throws Exception {
    try {
      log.info("初始化iov-service-base:Redis缓存");
      RestResponse restResponse = initCacheRemoteService.initCache();
      if (restResponse!=null&&restResponse.isFlag()){
        log.info("初始化iov-service-base:Redis缓存成功");
        return ReturnT.SUCCESS;
      }else{
        log.error("初始化iov-service-base:Redis缓存失败");
        return ReturnT.FAIL;
      }
    }catch(Exception e){
      log.error("初始化iov-service-base:Redis缓存失败", e);
      return ReturnT.FAIL;
    }
  }
}